import os
import unittest
import datetime
from library.HTMLTestRunnerNew import HTMLTestRunner
from common.handlepath import CASEDIR, REPORTDIR
from common.handle_email import sendemail
from BeautifulReport import BeautifulReport

date = datetime.datetime.now().strftime("%Y%m%d%H%M")
# 1.创建测试套件
suite = unittest.TestSuite()
# 2. 加载测试套件
loader = unittest.TestLoader()
# 通过路径进行加载测试用例
suite.addTest(loader.discover(CASEDIR))


# 3.执行用例（用unittest内置的方法）
report_file = os.path.join(REPORTDIR, date + "report.html")

# 创建执行对象并运行
runner = HTMLTestRunner(stream=open(report_file, "wb"),
                        title="全测试结果的报告",
                        description=date + "keyou项目最终报告",
                        tester="小郁")

runner.run(suite)

"""
# 发送邮件
sendemail(filename=report_file, title=date + "keyou项目测试结果的报告")


# 3.用BeautifulReport执行用例
br = BeautifulReport(suite)
# 生成报告
br.report(report_dir=REPORTDIR, filename=date + "report.html", description="keyou项目测试结果的报告")
"""

